home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH02 / PASFUNC2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-12-17  |  1.7 KB  |  67 lines

  1. program GenericFunc(input,output);
  2. const
  3.      hex = ['a'..'f', 'A'..'F'];
  4.      decimal= ['0'..'9'];
  5.  
  6. var
  7.    a, b, c, d:integer;
  8.    fresult:integer;
  9.    func: integer;
  10.  
  11.  
  12. (* Here is a second version of the Pascal generic function that uses *)
  13. (* the features of Turbo Pascal to simplify the program.             *)
  14.  
  15.  
  16. function ReadFunc:integer;
  17. var ch:char;
  18.     i, val:integer;
  19. begin
  20.  
  21.      write('Enter function number (hexadecimal): ');
  22.      repeat
  23.  
  24.            read(ch);
  25.            func := 0;
  26.            if not eoln then begin
  27.  
  28.               if (ch in Hex) then
  29.                  func := (func shl 4) + (ord(ch) and 15) + 9
  30.               else if (ch in Decimal) then
  31.                  func := (func shl 4) + (ord(ch) and 15)
  32.               else write(chr(7));
  33.  
  34.            end;
  35.      until eoln;
  36.      ReadFunc := func;
  37. end;
  38.  
  39.  
  40. (* Generic - Computes the generic logical function specified by *)
  41. (*           the function number "func" on the four input vars  *)
  42. (*           a, b, c, and d.  It does this by returning bit     *)
  43. (*           d*8 + c*4 + b*2 + a from func.  This version re-   *)
  44. (*           lies on Turbo Pascal's shift right operator and    *)
  45. (*           its ability to do bitwise operations on integers.  *)
  46.  
  47. function Generic(func,a,b,c,d:integer):integer;
  48. begin
  49.           Generic := (func shr (a + b*2 + c*4 + d*8)) and 1;
  50. end;
  51.  
  52.  
  53. begin (* main *)
  54.  
  55.       repeat
  56.  
  57.             fresult := ReadFunc;
  58.             if (fresult <> 0) then begin
  59.  
  60.                write('Enter values for D, C, B, & A (0/1):');
  61.                readln(d, c, b, a);
  62.                writeln('The result is ',Generic(func,a,b,c,d));
  63.  
  64.             end;
  65.       until fresult = 0;
  66.  
  67. end.